
import approveApi from '@/api/src/approve'
import { get } from 'sortablejs'
export default {
  data () {
    return {
      initMethodsKey: 'getInfo',
      showApproveDialog: false
    }
  },
  computed: {
    approveObj: {
      get () {
        return {
          businessId: '180',
          processType: '1',
          remark: '',
          approveType: '0'
        }
      },
      set () {
        console.log('approveObj set')
      }
    }
  },
  methods: {
    // 撤销审批
    onRevocation () {
      this.$msg.confirm('该审批流已开始，确定撤销审批？', '撤销审批').then(async () => {
        await approveApi.cancel({...this.approveObj})
        this.$msg.success()
        this[this.initMethodsKey]()
        this.$emit('after-save')
      })
    },

    async afterApprove (obj) {
      this.approveObj.remark = obj.remark
      if (+this.approveObj.type === 1) {
        // type '1'通过 '0'驳回
        await approveApi.agree({...this.approveObj})
      } else {
        await approveApi.refuse({...this.approveObj})
      }
      this.$refs.approveDialog.dialogClose()
      this.$msg.success()
      this[this.initMethodsKey]()
      this.$emit('after-save')
    },
    // 审批驳回或通过
    onApproved (type) {
      this.approveObj.approveType = type
      this.showApproveDialog = true
    }
  }
}
